package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: SkuManageController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-08-20 11:05
 * @Version 1.0
 */

@Api(tags = "sku操作")
@RestController
@RequestMapping("/admin/product")
public class SkuManageController {

 @Autowired
 private ManageService manageService;
 /**
  * 保存销售属性-销售属性值
  * @return
  */
 @PostMapping("/saveSkuInfo")
 public Result savaSkuInfo(@RequestBody SkuInfo skuInfo){
//调用服务层方法
  manageService.savaSkuInfo(skuInfo);
  return Result.ok();
}

 /**
  * 查询skuinfo
  * @param page
  * @param limit
  * @param skuInfo
  * @return
  */
 @GetMapping("/list/{page}/{limit}")
 public Result getSkuInfoList(@PathVariable Long page,
                              @PathVariable Long limit,
                              SkuInfo skuInfo ){
  // 创建page对象
 Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
 // 调用服务层
 IPage<SkuInfo> iPage = manageService.getSkuInfoList(skuInfoPage,skuInfo.getCategory3Id());
 return  Result.ok(iPage);
 }

 /**
  * 商品上架
  * @param skuId
  * @return
  */
 @GetMapping("/onSale/{skuId}")
 public Result onSale(@PathVariable Long skuId){
manageService.onSale(skuId);
  return Result.ok();
 }
 /**
  * 商品下架
  * @param skuId
  * @return
  */
 @GetMapping("/cancelSale/{skuId}")
 public Result cancelSale(@PathVariable Long skuId){
  manageService.cancelSale(skuId);
  return Result.ok();
 }
}
